<template>
    <view class="Contain"> <!-- Contain Start aspectFill -->
	<!-- widthFix  aspectFit aspectFill -->
        <view class="uswiper" style="width:100%; overflow: hidden; margin:0px; padding:0px;">
            <u-swiper :list="list.data" bgColor="#FFFFFF" previousMargin="0" nextMargin="0" height="400" @click="PrevImage" imgMode="aspectFit"></u-swiper>
        </view>
        <view class="price" v-if="ProductInfo.data!=null">
            <block v-if="ProductInfo.data.productdiscountprice!=null && ProductInfo.data.productdiscountprice!=''">
                <view class="a">
                    <text>¥</text>
                    {{ ProductInfo.data.productdiscountprice }}
                </view>
                <view class="b" v-if="ProductInfo.data.productdiscountprice<ProductInfo.data.productprice">
                    <text>¥</text>
                    {{ ProductInfo.data.productprice }}
                </view>
            </block>
            <block v-else>
                <view class="a">
                    <text>¥</text>
                    {{ ProductInfo.data.productprice }}
                </view>
                <view class="b"></view>
            </block>
            <view class="c" @click="addFav(ProductInfo.data.id)">已售{{selled}}件 <!-- <u-icon :name="favIcon" color="#ff6600" size="22"></u-icon>收藏 --></view>
        </view> <!-- price End -->

        <view class="title" v-if="ProductInfo.data!=null">【{{ ProductInfo.data.productname }}】{{ ProductInfo.data.productdesc }}</view>
        <!-- <view class="desc">{{ProductInfo.typeKey}}</view> -->

        <!-- 间隔槽 -->
        <u-gap height="15" bg-color="#F7F9FD" margin-top="20" margin-bottom="20"></u-gap>
        <view class="guige mp">
            <u-row gutter="16">
                <u-col span="2" text-align="center">
                    <view class="gray">规格</view>
                </u-col>
                <u-col span="3" text-align="left">
                    <view style="padding-left:10rpx;" class="stext">1件</view>
                </u-col>
                <u-col span="6" text-align="right">
                    <view><!-- <u-icon name="arrow-right" color="#ccc" size="28"></u-icon> --></view>
                </u-col>
            </u-row>
        </view>
        <view class="service mp">
            <u-row gutter="16">
                <u-col span="2" text-align="center">
                    <view class="gray">服务</view>
                </u-col>
                <u-col span="3" text-align="left">
                    <view class="stext">商家包邮</view>
                </u-col>
                <u-col span="4" text-align="left">
					<!-- 7天无理由退货 -->
                    <view class="stext">破损包退换</view>
                </u-col>
				<u-col span="3" text-align="left">
					<!-- 晚发陪 -->
				    <view class="stext">闪电发货</view>
				</u-col>
            </u-row>
        </view>
		<!-- <view class="service mp">
            <u-row gutter="16">
                <u-col span="2" text-align="center">
                    <view class="gray"></view>
                </u-col>
                <u-col span="3" text-align="left">
                    <view class="stext">15天价保</view>
                </u-col>
				<u-col span="4" text-align="left">
				    <view class="stext">破损包退换</view>
				</u-col>
				<u-col span="3" text-align="left">
				    <view class="stext">闪电退款</view>
				</u-col>
            </u-row>
        </view> -->
        <!-- 评价 -->
 
		
		
		<!-- 评价 
		<u-gap height="15" bg-color="#F7F9FD" margin-top="20" margin-bottom="20"></u-gap>
		<view class="pingjia" @click="goComment">
			<view class="pjTitle">
				<view class="a">商品评价 2000+条</view>
				<view class="b">好评度88%<u-icon name="arrow-right" color="#999" size="12"></u-icon></view>
			</view>
			<view>
				 <u-scroll-list indicatorColor="#fff0f0" indicatorActiveColor="#f56c6c" style="width:2000px;overflow-x:scroll;">
				        <view class="pjbox" v-for="(item, index) in pjlist" :key="index">
				           <image :src="item.thumb"></image> 
						   <view class="pjbox_left">
							   <u-row justify="space-between" align="center">
								   <u-col span="3" justify="center" textAlign="center">
									   <view class="userimg">
										   <image :src="item.headimg" style="width:60rpx; height:60rpx; border-radius:100%;"></image>
										</view>
								   </u-col>
								   <u-col span="9" justify="start" textAlign="left">
									   <view class="username">{{item.username}}</view>
									   <view class="star">
										   <u-rate :gutter="0" :size="13" readonly :count="item.count" v-model="item.value"></u-rate>
									   </view>
								   </u-col>
							   </u-row>
							   <view class="desc"><text>{{item.desc}}</text></view>
						   </view>
						   <view class="pjbox_right">
						   		<image mode="aspectFill" style="width:100px; height:100px;border-radius:10rpx;" 
								:src="item.pjimgs[0]" @click="preViewPjimgs(item)">
								</image>
								<view class="tags">{{item.pjimgs.length}}张</view>
						   </view>
				        </view>
				    </u-scroll-list>
			</view>
		</view>
		-->

        <u-gap height="15" bg-color="#F7F9FD" margin-top="20" margin-bottom="20"></u-gap>

        <view class="HomeAd">
            <u-row gutter="0">
                <u-col span="1.5" text-align="center">
                    <view>
                        <image :src="$globalConfig.shopLogo"></image>
                    </view>
                </u-col>
                <u-col span="7.5" text-align="left">
                    <view>{{$globalConfig.shopName}}</view>
                </u-col>
                <u-col span="3" text-align="right">
                    <!-- <view class="link">店铺首页</view> -->
                </u-col>
            </u-row>
        </view> <!-- HomeAd End -->

        <u-gap height="15" bg-color="#F7F9FD" margin-top="20" margin-bottom="0"></u-gap>

        <view class="detailContent py-2">
            <view class="tabs">
                <u-tabs :list="Tablist" :scrollable="false" :current="current" @change="change"></u-tabs>
            </view>

            <!-- 详情页 -->
            <view class="detailPage" v-if="isDetailPage===true">
				<!-- 文字图片介绍 -->
                <view  class="mt-2" v-for="(item,index) in AllList.data">
                   <image class="imagesyle" :src="item" mode="widthFix" @click="preViewImage(index)"></image>
				</view>
            </view> <!-- detailpage End -->

            <!-- 参数详情 -->
            <view class="paraPage" v-if="isDetailPage===false">
                <!-- <view class="title">产品参数</view> -->
				<!-- <view class="paras"><u-parse :content="productParas.data"></u-parse></view> -->
                <!-- <view class="gray" style="width:100%; text-align:center;">暂无相关参数</view> -->
                <!-- 参数详情 -->
                <view class="paralist">
					<view style="margin-top:10px;">
						<u-row gutter="16">
							<u-col span="3.5" text-align="right">
								<view>生产商 :</view>
							</u-col>
							<u-col span="8.5" text-align="left">
								<view>广东医科大学 & 恒河技术联合开发</view>
							</u-col>
						</u-row>
					</view>
					<view style="margin-top:10px;">
						<u-row gutter="16">
							<u-col span="3.5" text-align="right">
								<view>商品名称 :</view>
							</u-col>
							<u-col span="8.5" text-align="left">
								<view>天然水合氢离子水</view>
							</u-col>
						</u-row>
					</view>
					<view style="margin-top:10px;">
						<u-row gutter="16" style="margin-bottom:10px;">
							<u-col span="3.5" text-align="right">
								<view>规格 :</view>
							</u-col>
							<u-col span="8.5" text-align="left">
								<view>饮用水330mL*12瓶/箱</view>
							</u-col>
						</u-row>
					</view>
					<view style="margin-top:10px;">
						<u-row gutter="16" style="margin-bottom:10px;" align="top">
							<u-col span="3.5" text-align="right">
								<view>生产地 :</view>
							</u-col>
							<u-col span="8.5" text-align="left">
								<view>江苏连云港</view>
							</u-col>
						</u-row>
					</view>
					<view style="margin-top:10px;">
						<u-row gutter="16" style="margin-bottom:10px;" align="top">
							<u-col span="3.5" text-align="right">
								<view>颜色 :</view>
							</u-col>
							<u-col span="8.5" text-align="left">
								<view>白色透塑料装</view>
							</u-col>
						</u-row>
					</view>
					<view style="margin-top:10px;">
						<u-row gutter="16" style="margin-bottom:10px;" align="top">
							<u-col span="3.5" text-align="right">
								<view>保质期 :</view>
							</u-col>
							<u-col span="8.5" text-align="left">
								<view>12个月</view>
							</u-col>
						</u-row>
					</view>
					<view style="margin-top:10px;">
						<u-row gutter="16" style="margin-bottom:10px;" align="top">
							<u-col span="3.5" text-align="right">
								<view>国产/进口 :</view>
							</u-col>
							<u-col span="8.5" text-align="left">
								<view>国产</view>
							</u-col>
						</u-row>
					</view>
                </view> 
            </view> 

        </view> <!-- detailContent End -->


        <!-- 加入购物车 -->
        <view class="addToCart">
            <u-popup :show="showCart" mode="bottom" :closeOnClickOverlay="true" @close="closeCart" :height="shopCartPopuHeight">
                <view class="CartOption">
                    <!-- 头部 -->
                    <view class="Head">
                        <u-row gutter="16">
                            <u-col span="3" text-align="center">
                                <view class="pimg" @click="PrevImage_II">
                                    <image class="pimage" v-if="selected_specification_image!=''" :src="selected_specification_image"
                                           mode="aspectFit"></image>
                                    <image class="pimage" v-else src="https://aigxyy.oss-cn-shenzhen.aliyuncs.com/images/shopimg/none.png" mode="aspectFit"></image>
                                </view>
                            </u-col>
                            <u-col span="9" text-align="left">
								<view class="Pform">
									<view class="shopprice"> <text class="texticon">¥</text>{{shopPrice}}</view>
									<view class="originPrice">原价: {{originalPrice}}</view>
									<view class="kucun gray">剩余{{ inventory }}件</view>									
								</view> <!-- Pform End -->
                            </u-col>
                        </u-row>
                        <view class="close" @click="showCart=false">
                            <u-icon name="close" color="#999" size="33"></u-icon>
                        </view>
                    </view>
                    <!-- 规格 -->
                    <view class="specifications">
                        <view class="tit">规格</view>
                        <view class="para">
                            <!-- 库存不足，灰色显示 item.stock<=0?'NoData':'' -->
                            <view v-for="(item,index) in specification.data" class="block paralists" @click="selectsp(index)"
                                  :class="[specification_index===index?'selected':'',item.stock<=0?'NoData':'']">
                                <view>{{ item.name }}</view>
                                <view class="needDoctor" v-if="item.needDoctor>0">授</view>
                            </view>
                        </view>
                    </view>
                    <!-- 型号 -->
                    <!-- <view class="specifications">
                        <view class="tit">型号</view>
                        <view class="para">
                            <view class="block" v-for="(item,index) in model" @click="selectmodel(index)" :class="model_index===index?'selected':''">{{item}}</view>
                        </view>
                    </view> -->
                    <view class="buybtn">
                        <u-row gutter="16">
                            <u-col span="6" textAlign="left" justify="flex-start">
                                <view class="black mid">购买数量</view>
                            </u-col>
                            <u-col span="6" textAlign="right" justify="flex-end">
                                <view style="text-align:right; display:flex; justify-content:flex-end;">
                                    <u-number-box v-model="value" disabledInput :min="1" @change="valChange"></u-number-box>
                                </view>
                            </u-col>
                        </u-row>
                    </view> <!-- buybtn End -->

                    <view class="comfirmbtn" @click="comfirmbtn">确定</view>

                </view> <!-- CartOption End -->
            </u-popup>
			
			
        </view> <!-- addToCart End -->
		
		
		
		<BottomShoppingCartBar :isDisabledCart="isDisabledCart" :BuyNum="BuyNum" @OpenCart="ProcessCart"></BottomShoppingCartBar>

    </view> <!-- Contain End -->
</template>

<script setup lang="ts">
import { ref,reactive } from 'vue'
import { GoUrl,Toast } from '@/utils/utils'
import {onShow} from '@dcloudio/uni-app'
import { onLoad } from '@dcloudio/uni-app'
import { userStore } from '@/stores/userStore'	
const userstore = userStore();

const addFavouriteData=()=>{
	
}

const deleteFavouritesData=()=>{
	
}

const getProductInfoById=()=>{
	
}

let favIcon=ref("star");
let isHaveFaved=ref(false); //是否已修改
let shopDetail=reactive<any>({});
let ProductInfo=reactive<any>({data:
		{
				"id":"1",
				'productimg':'https://guangxins.oss-cn-shenzhen.aliyuncs.com/images/water/w3-3.jpg',
				"productdiscountprice":398,
				"productprice":498,
				"productname":"天然水合氢离子水（H3O+）",
				"productdesc":"强力清除自由基/护肝解酒/抗衰老/抗疲劳/消炎症/年轻态 饮用天然弱碱性水330mL*12/箱",
				"description":"<div><img src='https://aigxyy.oss-cn-shenzhen.aliyuncs.com/images/shopimg/sss1.png' style='width:100%;' /></div><div><img src='https://aigxyy.oss-cn-shenzhen.aliyuncs.com/images/shopimg/sss2.png' style='width:100%;' /></div>" 
		}
});
let isDisabledCart=ref(false);
let shopPrice=ref("398");   //商品价格
let originalPrice=ref("498"); //原价
let shopCartPopuHeight=ref("700"); //购物车弹窗默认高度

let AllList=reactive<any>({data:[]});

let list=reactive<any>({data:
	[ //轮播图
		"https://guangxins.oss-cn-shenzhen.aliyuncs.com/images/water/w3-3.jpg",
		"https://guangxins.oss-cn-shenzhen.aliyuncs.com/images/water/w5-5.png",
		"https://guangxins.oss-cn-shenzhen.aliyuncs.com/images/water/w1-1.png",
		"https://guangxins.oss-cn-shenzhen.aliyuncs.com/images/water/w2-2.png",
		"https://guangxins.oss-cn-shenzhen.aliyuncs.com/images/water/w6-6.png"
	]
});
//详情
let detailList=reactive<any>({data:
	[ //轮播图
		"https://guangxins.oss-cn-shenzhen.aliyuncs.com/images/water/d1.png",
		"https://guangxins.oss-cn-shenzhen.aliyuncs.com/images/water/d2.png",
		"https://guangxins.oss-cn-shenzhen.aliyuncs.com/images/water/d3.png",
		"https://guangxins.oss-cn-shenzhen.aliyuncs.com/images/water/d4.png",
		"https://guangxins.oss-cn-shenzhen.aliyuncs.com/images/water/d5.png",
		"https://guangxins.oss-cn-shenzhen.aliyuncs.com/images/water/d6.png"
	]
});
let textImagePng=ref('https://guangxins.oss-cn-shenzhen.aliyuncs.com/images/water/tword.png'); //文字图片介绍
let Tablist=reactive<any>([
	{
		name: '图文详情'
	}, {
		name: '商品参数'
	}
]);
let pjlist=reactive<any>([
		{
			headimg:"https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fsafe-img.xhscdn.com%2Fbw1%2F8ca61ee2-dbe4-41a7-93e1-893930c9a3c4%3FimageView2%2F2%2Fw%2F1080%2Fformat%2Fjpg&refer=http%3A%2F%2Fsafe-img.xhscdn.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1702963507&t=a5ccbe099ea3420acc45302d6e7c9e4d",
			username:"小**美",
			count:5,
			value:5,
			desc:"口味很好，同时也说很好喝...",
			thumb: "https://cdn.uviewui.com/uview/goods/1.jpg",
			pjimgs:[
				"https://guangxins.oss-cn-shenzhen.aliyuncs.com/images/shop/nongfu1.png",
				"https://guangxins.oss-cn-shenzhen.aliyuncs.com/images/shop/nongfu2.png"
			] //评论图集
		}, {
			headimg:"https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fsafe-img.xhscdn.com%2Fbw1%2Ffcde7783-032d-4e0f-a4f7-2da03d10c425%3FimageView2%2F2%2Fw%2F1080%2Fformat%2Fjpg&refer=http%3A%2F%2Fsafe-img.xhscdn.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1702979599&t=ef92d12d6e65c2418ae63c9f57c4ee30",
			username:"小**爱",
			count:5,
			value:1,
			desc:"味道还行...",
			thumb: "https://cdn.uviewui.com/uview/goods/2.jpg",
			pjimgs:[
				"https://guangxins.oss-cn-shenzhen.aliyuncs.com/images/shop/nongfu1.png",
				"https://guangxins.oss-cn-shenzhen.aliyuncs.com/images/shop/nongfu2.png"
			] //评论图集
		}, {
			headimg:"https://img2.baidu.com/it/u=2229997024,3339657040&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=500",
			username:"花**花",
			count:5,
			value:2,
			desc:"是我喜欢的那种水味...",
			thumb: "https://cdn.uviewui.com/uview/goods/3.jpg",
			pjimgs:[
				"https://guangxins.oss-cn-shenzhen.aliyuncs.com/images/shop/nongfu1.png",
				"https://guangxins.oss-cn-shenzhen.aliyuncs.com/images/shop/nongfu2.png"
			] //评论图集
		}, {
			headimg:"https://img1.baidu.com/it/u=2425296538,2255658679&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=501",
			username:"晓**晓",
			count:5,
			value:4,
			thumb: "https://cdn.uviewui.com/uview/goods/4.jpg",
			desc:"一般般，没有想象中那么好~",
			pjimgs:[
				"https://guangxins.oss-cn-shenzhen.aliyuncs.com/images/shop/nongfu1.png",
				"https://guangxins.oss-cn-shenzhen.aliyuncs.com/images/shop/nongfu2.png"
			] //评论图集
		}, {
			headimg:"https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fsafe-img.xhscdn.com%2Fbw1%2Fb1344a0b-961e-4326-87f8-049869fd5729%3FimageView2%2F2%2Fw%2F1080%2Fformat%2Fjpg&refer=http%3A%2F%2Fsafe-img.xhscdn.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1702979758&t=48b7cddac551238d2eb5d10a164b297e",
			username:"小**杏",
			count:5,
			value:2,
			desc:"香香哒，喝了一口，很丝滑!!!",
			thumb: "https://cdn.uviewui.com/uview/goods/5.jpg",
			pjimgs:[
				"https://guangxins.oss-cn-shenzhen.aliyuncs.com/images/shop/nongfu1.png",
				"https://guangxins.oss-cn-shenzhen.aliyuncs.com/images/shop/nongfu2.png"
			] //评论图集
		}
]);
let classifyId=ref("");
let specification=reactive<any>({data:[
	{
		'picUrl':'https://guangxins.oss-cn-shenzhen.aliyuncs.com/images/water/w3-3.jpg',
		'originalPrice':498,
		'discountPrice':398,
		'stock':8,
		'name':'天然水合氢离子水(H3O+) 330ml*12瓶/箱',
		'needDoctor':0
	}
]});
let specification_index=ref(0);
let selected_specification_image=ref("https://guangxins.oss-cn-shenzhen.aliyuncs.com/images/water/w3-3.jpg");
let selected_specification_name=ref("");
let selled=ref(88); //已售
let inventory=ref(99); //库存
let productParas=reactive<any>({data:null}) //HtmlContent内容
let model=reactive<string[]>(["大号", "小号"])
let model_index=ref(-1);
let current=ref(0);
let isDetailPage=ref(true);
let showCart=ref(false);
let value=ref(1);
let BuyNum=ref(0);
let Act=ref("");
let isExecuting=ref(false);

//是否直接购买模式
let directByMode=ref(false); 
//购物车对象列表
let cartList=reactive<any>({});

//微信登陆码
let loginCode=ref("");
let isGetLoginCode=ref(false);

const goComment=()=>{
	uni.$tools.GoUrl("/pages/shop_comment/shop_comment");
}

const preViewImage=function(index:Number){
	console.log("预览图片:",AllList.data[index]);
	uni.previewImage({
		current:AllList.data[index],
		urls:AllList.data,
	})
}

const preViewImageII=function(imgUrl:string){
	uni.previewImage({
		current:imgUrl,
		urls:[imgUrl],
	})
}




const preViewPjimgs=function(item:Object){
	uni.previewImage({
		current:item.pjimgs[0],
		urls:item.pjimgs,
	})
}



const getLoginCode=()=>{
	if(isGetLoginCode.value===false){
		uni.login({
			  provider: 'weixin',
			  onlyAuthorize:true,
			  success:e=> {
				//登录。注册会员信息
				if(e.errMsg==='login:ok' && e.code!=null){
					loginCode.value=e.code;
					isGetLoginCode.value=true;
					console.log("微信 login code:",loginCode.value);	
					userLogin();						
				}
			  }
		});	
	}
}

//匿名登录
const userLogin=()=>{
	let paraData={
		logincode:loginCode.value,
	}
	console.log("登录参数:",paraData);
	uni.$tools.Reqeust('/shopApi/shopLogin',paraData,'POST').then((res:any)=>{
			console.log('登录结果:',res);
			if (res.data.code == 200) {
				//保存用户信息
				uni.setStorageSync("token",res.data.data.token);
				uni.setStorageSync("shopuserinfo",res.data.data);
			}else{
				uni.$tools.Toast(res.data.msg);
			}
	})
}

onLoad((opt:any)=>{
	getLoginCode(); //匿名登录，用户无感知
	if(opt.pid && opt.pid!=''){
		//查找用户之前是否已收藏缓存
		isHaveFaved.value=userstore.isFavouritesExist(parseInt(opt.pid));
		console.log("商品之前是否已收藏",isHaveFaved.value);
		if(isHaveFaved.value){
			favIcon.value="star-fill";
		}else{
			favIcon.value="star";
		}
	}
	
	
	//合并图片
	detailList.data.forEach(item=>{
		AllList.data.push(item);
	});
	
	list.data.forEach(item=>{
		AllList.data.push(item);
	});
	
	AllList.data.push(textImagePng.value);
	
})



onShow(()=>{
	uni.setStorageSync("keyid","shop");
	BuyNum.value=0;
	uni.removeStorageSync("BuyProductInfo");
	uni.removeStorageSync("cartProductList");
})





//添加收藏
const addFav=async (productId:number)=>{
	
	if(userstore.userData.isLogin==false){
		Toast("请登录后操作");
		setTimeout(()=>{
			GoUrl("../mine/mine",2);
		},1000);
		return;
	}
	
	//判断之前是否已收藏过
	isHaveFaved.value=userstore.isFavouritesExist(productId);
	if(isHaveFaved.value){
		//已收藏
		let favId:number=userstore.getCurFavId(); // getCurFavId 依赖于 isFavouritesExist
		let res:any=await deleteFavouritesData(favId);
		if(res.data.code===200){
			favIcon.value="star";
			userstore.removeFavourites(favId); //删除缓存
		}
	}else{
		//未收藏
		let userId:number=userstore.userData.userinfo.id || -1;
		if(userId!=-1){
			let res:any=await addFavouriteData(userId,productId);
			console.log("收藏res==>",res);
			if(res.data.code===200){
				favIcon.value="star-fill";
				isHaveFaved.value=true;
				let FavouritesData:favouritesType={
						favId:res.data.favId,
						userId:userId,
						productId:productId
				}
				userstore.addFavourites(FavouritesData);
				Toast("已收藏");
			}
		}		
	}
}


const closeCart=()=>{
	showCart.value=false;
}
//放大预览轮播图
const PrevImage=(e:any)=>{
	console.log(e,list);
	//重新改变list架构适应预览接口
	let Temp =reactive<any>([]);
	list.data.forEach((item:any) => {
		Temp.push(item);
	})
	list.data = Temp;
	uni.previewImage({
		urls:list.data,
		current:list.data[e],
	});
}
//放大预览轮播图
const PrevImage_II=()=>{
	let Temp = reactive<any>([]);
	Temp.push(selected_specification_image.value);
	uni.previewImage({
		urls: Temp,
		current: Temp[0],
	});
}

const selectsp=(index:number)=>{
	console.log("规格索引:",index,"对象:",specification.data[index]);
	specification_index.value = index;
	selected_specification_name.value = specification.data[index].name;
	selected_specification_image.value = specification.data[index].picUrl;
	//选择规格后，库存变化
	inventory.value = specification.data[index].stock;
	classifyId.value = specification.data[index].id;
	//更新追加的字段值
	ProductInfo.data.desc= specification.data[index].desc;
	ProductInfo.data.classifyId = specification.data[index].id;
	ProductInfo.data.classifyName = specification.data[index].name;
	ProductInfo.data.needDoctor = specification.data[index].needDoctor;
	ProductInfo.data.picUrl = specification.data[index].picUrl;
	//显示当前选中的价格
	if(specification.data[index].discountPrice!=null && specification.data[index].discountPrice!=""){
		shopPrice=specification.data[index].discountPrice;
		originalPrice=specification.data[index].originalPrice;
	}else{
		if(specification.data[index].originalPrice!=null && specification.data[index].originalPrice!=""){
			shopPrice.value=specification.data[index].originalPrice;
		}else{
			shopPrice.value="暂无售价"
		}						
	}
	console.log("选择的规格", specification, selected_specification_name);
	
	//保存选中的规格
	//uni.setStorageSync("specificationIndex",index);
}

const selectmodel=(index:number)=>{
     model_index.value = index;
}

const comfirmbtn=()=>{
	
	//当前规格库存不足
	if (inventory.value <= 0) {
		Toast("当前选择的商品规格库存不足");
		return;
	}
	showCart.value = false;

	//获取上次选择的的组件index
	/* if(uni.getStorageSync("specificationIndex")){
		specification_index=uni.getStorageSync("specificationIndex");
		ProductInfo.data.picUrl = specification.data[specification_index.value].picUrl;
	} */
	
	if (Act.value === '购物车') {
		
		directByMode.value=false;
		uni.setStorageSync("directByMode",directByMode.value);
		
		//这里要转换为购物车对应的字段
		/*
			id=BuyProductInfo.data.id;
			isOver=0; //保持默认
			checked=false; //保持默认
			discountPrice=BuyProductInfo.data.productdiscountprice;
			picUrl=BuyProductInfo.data.productimg;
			needDoctor=0; //这个字段默认0，可以忽略
			goodsName=BuyProductInfo.data.productname;
			classifyName=BuyProductInfo.data.productdesc; //商品描述
			num=BuyProductInfo.data.BuyNum;
		*/
	   
		ProductInfo.data.id=specification.data[specification_index.value].id; //这里是购物车模式的话，id=规格的id 非 产品id
		ProductInfo.data.productdiscountprice=specification.data[specification_index.value].discountPrice;   //规格的价格 -- 注意2者区别
		ProductInfo.data.productprice=specification.data[specification_index.value].originalPrice;
		ProductInfo.data.productimg = specification.data[specification_index.value].picUrl; //规格图 --  注意2者区别
		ProductInfo.data.productname=specification.data[specification_index.value].name;
		ProductInfo.data.productdesc=specification.data[specification_index.value].desc;
		ProductInfo.data.BuyNum = value.value;
		
		//删除属性
		delete ProductInfo.data.specificationDatas;
		
		
		console.log("当前选中商品信息id:",ProductInfo.data.id,ProductInfo.data);
		
		if(uni.getStorageSync("ShopCartList")){
			cartList=uni.getStorageSync("ShopCartList");
			uni.setStorageSync("ShopCartList",cartList);
		}else{
			uni.setStorageSync("ShopCartList",ProductInfo.data);
		}
		
			
		//购物车组件响应值
		//购物车是一个列表存储
		if(uni.getStorageSync("ShopCartList")){
			let data=uni.getStorageSync("ShopCartList") || null;
			BuyNum.value=data===null?0:data.BuyNum;
		}else{
			BuyNum.value=1; //初始化，第一次赋值 
		}
		console.log("当前购买数量:",BuyNum.value);
		
		//GoUrl("../shop_order/shop_order");
		return;
	}
}


const change=(e:any)=>{
	current = e.index;
	//console.log(index)
	if (e.index === 1) {
		isDetailPage.value = false;
	} else {
		isDetailPage.value = true;
	}
}


const ProcessCart=(e:any)=>{
	console.log("接收购物车:", e);
	Act.value = e.act;
	//立即购买
	if (Act.value === '立即购买') {
		directByMode.value=true;
		uni.setStorageSync("directByMode",directByMode.value);
		//拼接追加一个购买数量
		ProductInfo.data.BuyNum = 1;
		console.log("当前选中商品信息:", ProductInfo.data);
		uni.setStorageSync("BuyProductInfo", ProductInfo.data);
		GoUrl("../shop_car/shop_car");
		return;
	}else{
		uni.setStorageSync("directByMode",false);
	}
	showCart.value = e.show; //显示购买规格
	uni.hideLoading();
}


const valChange=(e:any)=>{
	console.log('当前值为: ' + e.value)
	value.value = e.value;
}
</script>






<style>
page {
    padding-bottom: 200 rpx;
}
.u-icon__icon{ margin-left:0px !important; }
.vue-ref{ margin-top:10rpx !important; }
/* 去除图片周围的边框 */
image {
    display: block;
    border: none !important;
    outline: none !important;
}
</style>
<style scoped lang="scss">
@import "singleShopBuy.scss";
:deep(){
	.u-icon__icon{
		margin-left:20rpx;	
	}
	.u-swiper{
		width:100.5% !important;
	}
	.u-swiper__wrapper__item{
		margin:0px !important;
		padding:0px !important;
		border:0px !important;
		outline: 0px !important;
		top:-2px;
		left:-1px;
	}
	.u-swiper__wrapper__item,
	.u-swiper__wrapper__item::before,
	.u-swiper__wrapper__item::after,
	.u-swiper__wrapper__item__wrapper__image,
	.u-swiper__wrapper__item__wrapper__image::before,
	.u-swiper__wrapper__item__wrapper__image::after,
	{
		margin:0px !important;
		padding:0px !important;
		border:none;
		box-shadow: 0px;
		outline: none;
	}
	.u-swiper__wrapper__item image{
		outline: none !important;
		border:none !important;
	}
}
</style>